<?php
ini_set('display_errors',0);
set_time_limit(0);
$s = microtime(true);
/**
 * date : 2012-2-13
 * 抓取
 * 友情链接网上电脑网络类的QQ
 * http://go9go.cn
 * 
 * 抓取网站的rp值在1以上
 * 
 * 存到当前目录的link.txt
 */


for($i=1;$i<=2;$i++){

	$output = get_url("http://go9go.cn/links/search.php?list=0&kw=&fields=0&typeid=&catid=0&pr=0&baidu=&alexa=&baidusnap=0&yahoolink=&linksnum=&x=79&y=13&page=2");
	echo $output;exit;
	//取得想要的数据放到$out[1]
	preg_match('/id="item_296231"(.+)class="pages/is',$output,$out);
	preg_match_all('/<table(.+?)<\/table>/s',$out[1],$arr);
	
	$str = null;
	foreach ($arr[1] as $value) {
		preg_match('/message\/\?uin=(.+)&Site=/is',$value,$qq);
	
		$str = $str . $qq[1]."\r\n";
	}

	$fp = fopen("link.txt", "a");
	fwrite($fp, $str);
	fclose($fp);
}
echo $str;

$time_sum = number_format(microtime(true) - $s, 3, '.', '');
echo "耗时:{$time_sum}秒,".($time_sum/60)."分,".($time_sum/3600)."小时";

function get_url($u){	
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $u);
	curl_setopt($curl, CURLOPT_COOKIE, 'AJSTAT_ok_pages=11; AJSTAT_ok_times=1; __utma=90055053.1175589510.1334044779.1334044779.1334044779.1; __utmb=90055053.11.10.1334044779; __utmc=90055053; __utmz=90055053.1334044779.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); Hm_lvt_9c13e29cbcd2ab2aa69b5d9602328f38=1334044853888; Hm_lpvt_9c13e29cbcd2ab2aa69b5d9602328f38=1334044853888; go9go_auth=VDdSZ1FjBjZUbVcxBgkCZlF1C2kGNlFwDzwPJlchVSUEL1NdADZTWABjXmsEOgdjVDNXNldgWzcIMAo0BDIDOlQyUjBRYQYwVDdXNgYyAmZRPgs8BjRRNQ9rD2xXb1VsBDVTYwAyUzA%3D; go9go_username=creatorwpy');
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	$file_contents = curl_exec($curl);
	curl_close($curl);
	return $file_contents;
}
